<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Parameters Interceptor</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="guides.html">Guides</a>&nbsp;&gt;&nbsp;<a href="core-developers-guide.html">Core Developers Guide</a>&nbsp;&gt;&nbsp;<a href="interceptors.html">Interceptors</a>&nbsp;&gt;&nbsp;<a href="parameters-interceptor.html">Parameters Interceptor</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Parameters Interceptor</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14064">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14064">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14064">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14064">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14064">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14064">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><p>This interceptor sets all parameters on the value stack.</p><p>This interceptor gets all parameters from {@link ActionContext#getParameters()} and sets them on the value stack by&#160;calling <code>ValueStack#setValue(String, Object)</code>, typically resulting in the values submitted in a form&#160;request being applied to an action in the value stack. Note that the parameter map must contain a String key and&#160;often containers a String[] for the value.</p><p>The interceptor takes one parameter named 'ordered'. When set to true action properties are guaranteed to be&#160;set top-down which means that top action's properties are set first. Then it's subcomponents properties are set.&#160;The reason for this order is to enable a 'factory' pattern. For example, let's assume that one has an action&#160;that contains a property named <code>modelClass</code>&#160;that allows to choose what is the underlying implementation of model.&#160;By assuring that <code>modelClass</code>&#160;property is set before any model properties are set, it's possible to choose model&#160;implementation during <code>action.setModelClass()</code>&#160;call. Similarly it's possible to use <code>action.setPrimaryKey()&#160;</code>property set call to actually load the model class from persistent storage. Without any assumption on parameter&#160;order you have to use patterns like <a shape="rect" href="preparable-interface.html">Preparable Interface</a>.</p><p>Because parameter names are effectively OGNL statements, it is important that security be taken in to account.&#160;This interceptor will not apply any values in the parameters map if the expression contains an assignment (=),&#160;multiple expressions (,), or references any objects in the context (#). This is all done in the <code>#acceptableName(String)</code>&#160;method. In addition to this method, if the action being invoked implements the&#160;<code>ParameterNameAware</code>&#160;interface, the action will be consulted to determine if the parameter should be set.<br clear="none">In addition to these restrictions, a flag ( <code>ReflectionContextState#DENY_METHOD_EXECUTION</code>&#160;) is set such that&#160;no methods are allowed to be invoked. That means that any expression such as <code>person.doSomething()</code>&#160;or&#160;<code>person.getName()</code>&#160;will be explicitly forbidden. This is needed to make sure that your application is not&#160;exposed to attacks by malicious users.</p><p>While this interceptor is being invoked, a flag ( <code>ReflectionContextState#CREATE_NULL_OBJECTS</code>&#160;) is turned&#160;on to ensure that any null reference is automatically created - if possible. See the type conversion documentation&#160;and the <code>InstantiatingNullHandler</code>&#160;javadocs for more information.</p><p>Finally, a third flag ( <code>XWorkConverter#REPORT_CONVERSION_ERRORS</code>&#160;) is set that indicates any errors when&#160;converting the the values to their final data type (String[] -&amp;gt; int) an unrecoverable error occurred. With this&#160;flag set, the type conversion errors will be reported in the action context. See the type conversion documentation&#160;and the <code>XWorkConverter</code>&#160;javadocs for more information.<br clear="none"><br clear="none">If you are looking for detailed logging information about your parameters, turn on <code>DEBUG</code>&#160;level logging for this&#160;interceptor. A detailed log of all the parameter keys and values will be reported.<br clear="none"><br clear="none"></p><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Since XWork 2.0.2, this interceptor extends <code>MethodFilterInterceptor</code>, therefore being able to deal with <code>excludeMethods</code> / <code>includeMethods</code> parameters. See <a shape="rect" href="default-workflow-interceptor.html">Default Workflow Interceptor</a> for documentation and examples on how to use this feature.</p></div></div><p>For more information on ways to restrict the parameter names allowed, see the <code>ParameterNameAware</code>&#160;javadocs.</p><h2 id="ParametersInterceptor-Parameters">Parameters</h2><ul style="list-style-type: square;"><li><code>ordered</code>&#160;- set to true if you want the top-down property setter behaviour</li><li><code>acceptParamNames</code>&#160;- a comma delimited list of regular expressions to describe a whitelist of accepted parameter names.&#160;Don't change the default unless you know what you are doing in terms of security implications</li><li><code>excludeParams</code>&#160;- a comma delimited list of regular expressions to describe a blacklist of not allowed parameter names</li><li><code>paramNameMaxLength</code>&#160;- the maximum length of parameter names; parameters with longer names will be ignored; the default is 100 characters</li></ul><h2 id="ParametersInterceptor-Excludingparameters">Excluding parameters</h2><p>This interceptor can be forced to ignore parameters, by setting its <em>excludeParams</em> attribute. This attribute accepts a comma separated list of regular expressions. When any of these expressions match the name of a parameter, such parameter will be ignored by the interceptor. Interceptor stacks defined by Struts already exclude some parameters:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Default List of Parameters Excluded</b></div><div class="codeContent panelContent pdl">
<pre class="brush: html; gutter: false; theme: Default" style="font-size:12px;">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*
</pre>
</div></div><p>Below is an example of adding a parameter named submit to the list of parameters that should be excluded.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Setup Interceptor Stack To Exclude submit Parameter</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;interceptors&gt;
  &lt;interceptor-stack name="appDefault"&gt;
    &lt;interceptor-ref name="defaultStack"&gt;
       &lt;param name="exception.logEnabled"&gt;true&lt;/param&gt;
       &lt;param name="exception.logLevel"&gt;ERROR&lt;/param&gt;
       &lt;param name="params.excludeParams"&gt;dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,submit&lt;/param&gt;
    &lt;/interceptor-ref&gt;
  &lt;/interceptor-stack&gt;
&lt;/interceptors&gt;
		
&lt;default-interceptor-ref name="appDefault" /&gt;
</pre>
</div></div><h2 id="ParametersInterceptor-ExtendingtheInterceptor">Extending the Interceptor</h2><p>The best way to add behavior to this interceptor is to utilize the <code>ParameterNameAware</code>&#160;interface in your&#160;actions. However, if you wish to apply a global rule that isn't implemented in your action, then you could extend&#160;this interceptor and override the <code>#acceptableName(String)</code>&#160;method.</p><div class="confluence-information-macro confluence-information-macro-warning"><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Using <code>ParameterNameAware</code> could be dangerous as <code>ParameterNameAware#acceptableParameterName(String)</code> takes precedence over <code>ParametersInterceptor</code> which means if <code>ParametersInterceptor</code> excluded given parameter name you can accept it with <code>ParameterNameAware#acceptableParameterName(String)</code>.</p><p>The best idea is to define very tight restrictions with <code>ParametersInterceptor</code> and relax them per action with <code>ParameterNameAware#acceptableParameterName(String)</code></p></div></div><h2 id="ParametersInterceptor-Warningonmissingparameters">Warning on missing parameters</h2><p>When there is no setter for given parameter name, a warning message like below will be logged in devMode:</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'search' on 'class demo.ItemSearchAction: Error setting expression 'search' with value ['search', ]
Error setting expression 'search' with value ['search', ] - [unknown location]
	at com.opensymphony.xwork2.ognl.OgnlValueStack.handleRuntimeException(OgnlValueStack.java:201)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:178)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:152)
</pre>
</div></div><p>Thus is expected behaviour to allow developer to spot missing setter or typo in either parameter name or setter.</p><h2 id="ParametersInterceptor-Examples">Examples</h2><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;action name="someAction" class="com.examples.SomeAction"&gt;
  &lt;interceptor-ref name="params"/&gt;
  &lt;result name="success"&gt;good_result.ftl&lt;/result&gt;
&lt;/action&gt;</pre>
</div></div></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
